package com.cndw.kungfu.vo;

import java.util.Collection;
import java.util.HashMap;

import com.cndw.kungfu.config.Constants;
import com.cndw.kungfu.config.ConstantsRadio;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.Scene;
import com.cndw.kungfu.model.Context;

/**
 * 广播通知
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-9-30 下午4:08:01
 */
public class EventNotice extends HashMap<String, Object> {

	private static final long serialVersionUID = -1203945195455141333L;

	private static final String eventObject = "eventObject";
	private static final String eventAction = "eventAction";
	private static final String eventData = "eventData";

	/**
	 * 
	 * @param eventObject
	 *            事件对象
	 * @param eventAction
	 *            事件行为
	 */
	public EventNotice(String obj, String act) {
		put(eventObject, obj);
		put(eventAction, act);
	}

	public void comitData(Object data) {
		put(eventData, data);
	}

	public void broadcast(Long... playerId) {
		Context.getTcpServer().broadcast(this, ConstantsRadio.eventNotice, playerId);
	}

	public void broadcast(Collection<Long> ids) {
		Context.getTcpServer().broadcast(this, ConstantsRadio.eventNotice, ids);
	}

	public void broadcast(String idKey) {
		Context.getTcpServer().broadcast(this, ConstantsRadio.eventNotice, idKey);
	}

	public void broadCastAllOnLine() {
		broadcast(Constants.COMMRADIO);
	}

	/**
	 * 广播场景 场景内所有人广播 副本内也会广播给所有人.不仅仅是我的队伍
	 * 
	 * @param sceneId
	 * @param subLine
	 */
	public void broadcastScene(int sceneId, int subLine) {
		String idKey = Context.getSceneServer().getRadioKey(sceneId, subLine);
		Context.getTcpServer().broadcast(this, ConstantsRadio.eventNotice, idKey);
	}

	public void broadcastScene(Player player) {
		if (player == null) {
			return;
		}
		String idKey = Context.getSceneServer().getRadioKey(player.getSceneId(), player.getSubLine());
		Context.getTcpServer().broadcast(this, ConstantsRadio.eventNotice, idKey);
	}

	public void broadcastAllScene(int sceneId) {
		Scene scene = Context.getSceneServer().getSceneById(sceneId);
		if (scene != null) {
			broadcast(scene.getPlayerIds(0));
		}
	}

}
